#include<bits/stdc++.h>
using namespace std;

const int N=20005;
int n;
int l[N],r[N];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&l[i],&r[i]);
    }
    int dp[N][2];
    dp[1][1]=r[1]-1;
    dp[1][0]=2*r[1]-l[1]-1;
    for(int i=2;i<=n;i++){
        dp[i][0]=dp[i][1]=INT_MAX;
        //dp[i-1][1]->dp[i][0],dp[i][1]
        if(r[i-1]<=l[i]){
            dp[i][1]=min(dp[i][1],dp[i-1][1]+1+(r[i]-r[i-1]) );
            dp[i][0]=min(dp[i][0],dp[i-1][1]+1+(r[i]-r[i-1])+(r[i]-l[i]) );
        }
        else if(r[i-1]>=r[i]){
            dp[i][0]=min(dp[i][0],dp[i-1][1]+1+(r[i-1]-l[i]));
            dp[i][1]=min(dp[i][1],dp[i-1][1]+1+(r[i-1]-l[i])+(r[i]-l[i]));
        }
        else{
            dp[i][1]=min(dp[i][1],dp[i-1][1]+1+(r[i-1]-l[i])+(r[i]-l[i]));
            dp[i][0]=min(dp[i][0],dp[i-1][1]+1+(r[i]-r[i-1])+(r[i]-l[i]));
        }
        //dp[i-1][0]->dp[i][0],dp[i][1]
        if(l[i-1]<=l[i]){
            dp[i][1]=min(dp[i][1],dp[i-1][0]+1+(r[i]-l[i-1]) );
            dp[i][0]=min(dp[i][0],dp[i-1][0]+1+(r[i]-l[i-1])+(r[i]-l[i]) );
        }
        else if(l[i-1]>=r[i]){
            dp[i][0]=min(dp[i][0],dp[i-1][0]+1+(l[i-1]-l[i]));
            dp[i][1]=min(dp[i][1],dp[i-1][0]+1+(l[i-1]-l[i])+(r[i]-l[i]));
        }
        else{
            dp[i][1]=min(dp[i][1],dp[i-1][0]+1+(l[i-1]-l[i])+(r[i]-l[i]));
            dp[i][0]=min(dp[i][0],dp[i-1][0]+1+(r[i]-l[i-1])+(r[i]-l[i]));
        }
    }
    printf("%d",min(dp[n][0]+(n-l[n]),dp[n][1]+(n-r[n]) ) );
    return 0;
}
